// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network.packets.hit;

import java.nio.ByteBuffer;
import zombie.characters.HitReactionNetworkAI;
import zombie.characters.IsoGameCharacter;
import zombie.core.network.ByteBufferWriter;
import zombie.core.raknet.UdpConnection;
import zombie.network.packets.INetworkPacket;

public class Fall implements INetworkPacket {
    protected float dropPositionX;
    protected float dropPositionY;
    protected byte dropPositionZ;
    protected float dropDirection;

    public void set(HitReactionNetworkAI hitReaction) {
        this.dropPositionX = hitReaction.finalPosition.x;
        this.dropPositionY = hitReaction.finalPosition.y;
        this.dropPositionZ = hitReaction.finalPositionZ;
        this.dropDirection = hitReaction.finalDirection.getDirection();
    }

    public void set(float _dropPositionX, float _dropPositionY, byte _dropPositionZ, float _dropDirection) {
        this.dropPositionX = _dropPositionX;
        this.dropPositionY = _dropPositionY;
        this.dropPositionZ = _dropPositionZ;
        this.dropDirection = _dropDirection;
    }

    @Override
    public void parse(ByteBuffer b, UdpConnection connection) {
        this.dropPositionX = b.getFloat();
        this.dropPositionY = b.getFloat();
        this.dropPositionZ = b.get();
        this.dropDirection = b.getFloat();
    }

    @Override
    public void write(ByteBufferWriter b) {
        b.putFloat(this.dropPositionX);
        b.putFloat(this.dropPositionY);
        b.putByte(this.dropPositionZ);
        b.putFloat(this.dropDirection);
    }

    @Override
    public String getDescription() {
        return "\n\tFall [ direction="
            + this.dropDirection
            + " | position=( "
            + this.dropPositionX
            + " ; "
            + this.dropPositionY
            + " ; "
            + this.dropPositionZ
            + " ) ]";
    }

    public void process(IsoGameCharacter character) {
        if (this.isSetup() && character.getHitReactionNetworkAI() != null) {
            character.getHitReactionNetworkAI().process(this.dropPositionX, this.dropPositionY, (float)this.dropPositionZ, this.dropDirection);
        }
    }

    boolean isSetup() {
        return this.dropPositionX != 0.0F && this.dropPositionY != 0.0F;
    }
}
